/**
 * 控制显示和隐藏
 * */
function display(id) {
    var traget = document.getElementById(id);
    if (traget.style.display == "none") {
        traget.style.display = "";
    } else {
        traget.style.display = "none";
    }
}

/**
 * 选中标签
 * @returns {boolean}
 */
function tag_check(tag) {
    var tag_name = tag.firstChild.nodeValue.replace(/(^#*)|(#*$)/g, "");
    var tags = document.getElementsByName("tag");
    i = 0;
    while (i < tags.length) {
        if (tags[i].value == tag_name) {
            tags[i].removeNode(true);
            return;//直接返回
        }
        //console.log(tags[i].value);
        i++;
    }
    var html = "<input type='hidden' name='tag' value='" + tag_name + "'>";
//    console.log(html);
    form.insertAdjacentHTML("BeforeEnd", html);
}

window.onscroll = function () {
    if (Math.abs(document.body.clientHeight - document.documentElement.clientHeight) - 400 <=
        (document.documentElement.scrollTop || document.body.scrollTop)) {

        //判断是不是正在加载中
        if (document.getElementById("loading").style.display = "") {
            return;
        }
        document.getElementById("loading").style.display = "";//显示出来
        //Ajax加载
        var date = 0;
        var xmlhttp = new XMLHttpRequest();
        var lis = document.getElementsByTagName("li");
        var last = lis[lis.length - 2].childNodes;
        for (var i = 0; i < last.length; i++) {
            if (last[i].tagName && last[i].tagName.toLowerCase() == "time") {
                date = last[i].getAttribute('datetime');
            }
        }
        xmlhttp.open("GET", "/Ajax/" + date, true);
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    var text = xmlhttp.responseText;
                    var last_li = document.getElementById("last_li");
                    last_li.insertAdjacentHTML("BeforeBegin", text);
                }
                document.getElementById("loading").style.display = "none";//隐藏起来

            }
        };
        xmlhttp.send();
    }
};